using System.Collections.Generic;
using System.IO;
using Common;

namespace SProject.Program
{
	public class PreHeatSegment : BaseSegment
	{
		private string _Name = Utility.GetMessage("preheatsection");

		public string Name
		{
			get
			{
				return _Name;
			}
			set
			{
				_Name = value;
			}
		}

		public double Temperature { get; set; }

		public bool IsUse { get; set; }

		public PreHeatSegment()
		{
			IsUse = true;
			Temperature = 50.0;
		}

		public override int GetHashCode()
		{
			return base.GetHashCode();
		}

		public override bool Equals(object obj)
		{
			if (obj == null || !(obj is PreHeatSegment))
			{
				return false;
			}
			if (!IsUse && !((PreHeatSegment)obj).IsUse)
			{
				return true;
			}
			return Temperature == ((PreHeatSegment)obj).Temperature;
		}

		public override void Copy(BaseSegment BaseSegment)
		{
			PreHeatSegment preHeatSegment = BaseSegment as PreHeatSegment;
			if (preHeatSegment != null)
			{
				IsUse = preHeatSegment.IsUse;
				Temperature = preHeatSegment.Temperature;
			}
		}

		public override BaseSegment Clone()
		{
			PreHeatSegment preHeatSegment = new PreHeatSegment();
			preHeatSegment.Copy(this);
			return preHeatSegment;
		}

		public override void SaveToStream(StreamEx stream)
		{
			stream.Write(PropertyKey.Key_PreHeatSegment);
			List<PropertyKey> list = new List<PropertyKey>();
			List<byte[]> list2 = new List<byte[]>();
			list.Add(PropertyKey.Key_Temperature);
			list2.Add(BytesConverter.GetBytes(Temperature));
			list.Add(PropertyKey.Key_IsUse);
			list2.Add(BytesConverter.GetBytes(IsUse));
			stream.Write(PropertyKey.Key_Index);
			stream.WriteIndex(list, list2);
			stream.Flush();
		}

		public override bool ReadFromStream(StreamEx stream)
		{
			PropertyKey propertyKey = stream.ReadKey();
			if (propertyKey == PropertyKey.Key_PreHeatSegment)
			{
				propertyKey = stream.ReadKey();
				if (propertyKey == PropertyKey.Key_Index)
				{
					List<PropertyKey> keys;
					List<byte[]> dates;
					stream.ReadIndex(out keys, out dates);
					for (int i = 0; i < keys.Count; i++)
					{
						switch (keys[i])
						{
						case PropertyKey.Key_Temperature:
							Temperature = BytesConverter.BytesToDouble(dates[i]);
							break;
						case PropertyKey.Key_IsUse:
							IsUse = BytesConverter.BytesToBool(dates[i]);
							break;
						}
					}
					return true;
				}
				stream.Seek(-4L, SeekOrigin.Current);
			}
			stream.Seek(-4L, SeekOrigin.Current);
			return false;
		}
	}
}
